aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tools/mass test client/Program.cs
blob: bc30a1c5b47ec455f6f173ea8d00afbb6c2768e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
using System;
using System.Collections.Generic;
using System.IO;
using CommandLine.Utility;

namespace libsecondlife.TestClient
{
    public class CommandLineArgumentsException : Exception
    {
    }

    public class Program
    {

        private static void Usage()
        {
            Console.WriteLine("Usage: " + Environment.NewLine +
                    "MassTestClient.exe --first \"firstname\" --last \"lastname\" --pass \"password\" --contact \"youremail\" [--startpos \"sim/x/y/z\"] [--master \"master name\"] [--masterkey \"master uuid\"] [--loginuri] [--masscommandfile \"filename\"]" +
                    Environment.NewLine + Environment.NewLine + "MassTestClient.exe --loginfile \"filename\" --contact \"youremail\" [--master \"master name\"] [--masterkey \"master uuid\"] [--loginuri] [--masscommandfile \"filename\"]");
            Console.ReadLine();
        }

        private static List<string> getMassTestCommands()
        {
            List<string> givenCommands = new List<string>();
            Console.WriteLine("Please enter mass test commands to run in an infinite loop. Press enter to end the current command. Entering a blank command represents that you are done.");
            Console.WriteLine("");

            int curCommand = 0;
            string lastCommand = "NULL";
            while (lastCommand.Length > 0)
            {
                Console.Write("Command #" + curCommand + ">");
                lastCommand = Console.ReadLine().Trim();
                if (lastCommand.Length > 0)
                {
                    givenCommands.Add(lastCommand);
                    curCommand++;
                }
            }

            return givenCommands;
        }

        static void Main(string[] args)
        {
            Arguments arguments = new Arguments(args);

            ClientManager manager;
            List<LoginDetails> accounts = new List<LoginDetails>();
            LoginDetails account;
            string masterName = String.Empty;
            LLUUID masterKey = LLUUID.Zero;
            string file = String.Empty;
            string contact = String.Empty;
            string loginURI = "https://login.agni.lindenlab.com/cgi-bin/login.cgi";

            try
            {
                if (arguments["masterkey"] != null)
                {
                    masterKey = LLUUID.Parse(arguments["masterkey"]);
                }

                if (arguments["master"] != null)
                {
                    masterName = arguments["master"];
                }

                if (arguments["contact"] == null)
                    throw new CommandLineArgumentsException();

                contact = arguments["contact"];

                if (arguments["loginfile"] != null)
                {
                    file = arguments["loginfile"];

                    // Loading names from a file
                    try
                    {
                        using (StreamReader reader = new StreamReader(file))
                        {
                            string line;
                            int lineNumber = 0;

                            while ((line = reader.ReadLine()) != null)
                            {
                                lineNumber++;
                                string[] tokens = line.Trim().Split(new char[] { ' ', ',' });

                                if (tokens.Length >= 3)
                                {
                                    account = new LoginDetails();
                                    account.FirstName = tokens[0];
                                    account.LastName = tokens[1];
                                    account.Password = tokens[2];

                                    accounts.Add(account);

                                    // Leaving this out until we have per-account masters (if that
                                    // is desirable). For now the command-line option can 
                                    // specify the single master that TestClient supports

                                    //if (tokens.Length == 5)
                                    //{
                                    //    master = tokens[3] + " " + tokens[4];
                                    //}
                                }
                                else
                                {
                                    Console.WriteLine("Invalid data on line " + lineNumber +
                                        ", must be in the format of: FirstName LastName Password");
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Error reading from " + args[1]);
                        Console.WriteLine(e.ToString());
                        Console.ReadLine();
                        return;
                    }
                }
                else if (arguments["first"] != null && arguments["last"] != null && arguments["pass"] != null)
                {
                    // Taking a single login off the command-line
                    account = new LoginDetails();
                    account.FirstName = arguments["first"];
                    account.LastName = arguments["last"];
                    account.Password = arguments["pass"];

                    accounts.Add(account);
                }
                else
                {
                    throw new CommandLineArgumentsException();
                }
            }

            catch (CommandLineArgumentsException)
            {
                Usage();
                return;
            }

            if (arguments["loginuri"] != null)
            {
                Console.WriteLine("Please enter a login uri. If you enter nothing, AGNI grid is assumed:");
                string temp = Console.ReadLine();
                if (temp.Trim().Length > 0)
                {
                    loginURI = temp.Trim();
                }
            }

            List<string> massTestCommands = new List<string>();
            if (arguments["masscommandfile"] != null)
            {
                string massCommandFile = arguments["masscommandfile"];
                try
                {
                    using (StreamReader reader = new StreamReader(massCommandFile))
                    {
                        string line;

                        while ((line = reader.ReadLine()) != null)
                        {

                            line = line.Trim();
                            if (line.Length > 0)
                            {
                                massTestCommands.Add(line);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error reading from " + args[1]);
                    Console.WriteLine(e.ToString());
                    Console.ReadLine();
                    return;
                }
            }
            else
            {
                Console.Clear();
                massTestCommands = getMassTestCommands();
            }

            Console.Clear();
            if (massTestCommands.Count == 0)
            {
                Console.WriteLine("No mass commands entered; Normal 'TestClient' operation will be used");
            }
            else
            {
                Console.WriteLine("Detected " + massTestCommands.Count + " mass commands; MassTestClient operation will be used");
            }

            Console.WriteLine(loginURI);
            foreach (LoginDetails a in accounts)
            {
                a.MasterName = masterName;
                a.MasterKey = masterKey;
                a.LoginURI = loginURI;
            }

            // Login the accounts and run the input loop
            if (arguments["startpos"] != null)
            {
                manager = new ClientManager(accounts, contact, arguments["startpos"]);
            }
            else
            {
                manager = new ClientManager(accounts, contact);
            }


            manager.Run(massTestCommands);
        }
    }
}